package analysis.metrics;


import primitives.cluster.*;
import search.util.TreeLoader2;

import java.io.*;

public abstract class Metric{

	public double evaluate(ClusterHead ch){
		throw new RuntimeException("Metric.evaluate shouldn't ever be called");
	}
	
	public void proc(String[] args) throws IOException{
		String filename = args[0];

		ClusterHead tree = TreeLoader2.loadTreeFromSerial(new File(filename));
		
		if(tree == null){
			System.err.println("ERROR: Tree loaded from " + args[0] + " is null. Aborting metric dump.");
			System.exit(-0xBAD);
		}
		try{
			System.out.print (evaluate(tree));
		}catch(NullPointerException npe){
			System.err.println("Caught a NPE! for file " + args[0]);

			ClusterUtils.prettyPrintTree(tree);
			System.exit(-0xBEEF);
		}
		
	}

}